// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/maintain/api/PlanTaskApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/maintain/model/QueryPlanTaskListReq'
import OneClass from '@api/maintain/model/QueryPlanTaskDetailReq'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询任务列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryPlanTaskList', DTO)
    return [resp.comQuery.totalCount, resp.planTaskDto || []]
  },

  // —————————————————————————————— 单项 —————————————————————————————— //

  async getOne({ id }, TIP = '查询任务详情') {
    const DTO = CORE.grpcDTO(OneClass, { planTaskId: id })
    const resp = await CORE.grpc(TIP, CLIENT, 'queryPlanTaskDetail', DTO)
    return resp.planTaskDto || {}
  },
  transOne(obj) {
    obj.planTemplateItemDto.forEach((child) => {
      obj[`child_${child.id}`] = child.itemContent && child.workingStandards ? 'ready' : ''
    })
    return obj
  },
}
